home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / class / memory.d < prev    next >
Text File  |  1996-09-09  |  1KB  |  83 lines

  1.  
  2.  
  3. /*                                      
  4.  *
  5.  *      Copyright (c) 1996 Algorithms Corporation
  6.  *      3020 Liberty Hills Drive
  7.  *      Franklin, TN 37067
  8.  *
  9.  *      ALL RIGHTS RESERVED.
  10.  *
  11.  *      
  12.  *      
  13.  */
  14.  
  15.  
  16. defclass Memory {
  17.     unsigned    iSize;
  18.     void        *iPtr;
  19. };
  20.  
  21. #include <string.h>
  22.  
  23. cmeth    gNewWithInt(int size)
  24. {
  25.     object    obj = gNew(super);
  26.     accessIVsOf(obj);
  27.     iSize = (unsigned) size;
  28.     iPtr = calloc(iSize ? iSize : 1, sizeof(char));
  29.     if (!iPtr)
  30.         gError(Dynace, "Dynace: out of memory.");
  31.     return obj;
  32. }
  33.  
  34. imeth    gDispose, gDeepDispose, gGCDispose ()
  35. {
  36.     if (iPtr)
  37.         free(iPtr);
  38.     return gDispose(super);
  39. }
  40.  
  41. imeth    void    *gPointerValue()
  42. {
  43.     return iPtr;
  44. }
  45.  
  46. imeth    int    gSize()
  47. {
  48.     return iSize;
  49. }
  50.  
  51. imeth    gResize(int size)
  52. {
  53.     iSize = (unsigned) size;
  54.     iPtr = realloc(iPtr, iSize ? iSize : 1);
  55.     if (!iPtr)
  56.         gError(Dynace, "Dynace: out of memory.");
  57.     return self;
  58. }
  59.  
  60. imeth    gDeepCopy, gCopy ()
  61. {
  62.     object    cpy = gNewWithInt(CLASS, (int) iSize);
  63.     ivType    *iv2 = ivPtr(cpy);
  64.     memcpy(iv2->iPtr, iPtr, iSize);
  65.     return cpy;
  66. }
  67.  
  68.  
  69.  
  70. /*                                      
  71.  *
  72.  *      Copyright (c) 1996 Algorithms Corporation
  73.  *      3020 Liberty Hills Drive
  74.  *      Franklin, TN 37067
  75.  *
  76.  *      ALL RIGHTS RESERVED.
  77.  *
  78.  *      
  79.  *      
  80.  */
  81.  
  82.  
  83.